package com.neusoft.service.impl;

import com.neusoft.dao.MenuDao;
import com.neusoft.pojo.Menu;
import com.neusoft.service.MenuService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @Author Miracle WYC
 * @Date 2022/4/27 10:58
 * @Version 1.0
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Resource
    MenuDao menuDao;

    @Override
    public List<Menu> selectMenuList(Menu menu) {
        return menuDao.selectMenuList(menu);
    }

    @Override
    public List<Menu> selectMenuById(String id) {
        return menuDao.selectMenuById(id);
    }

    @Override
    public int updateMenu(Menu menu) {
        return menuDao.updateMenu(menu);
    }

    @Override
    public int insertMenu(Menu menu) {
        /*判断是新增的用户且 不是空数据的*/
        if (StringUtils.isNotEmpty(menu.getMenuName()) ){
            /*设置随机UUID*/
            menu.setId(UUID.randomUUID().toString().replace("-",""));
            /*调用Dao数据*/
            return menuDao.insertMenu(menu);
        }
        return 2;
    }

    @Override
    public int deleteMenuById(String id) {
        return menuDao.deleteMenuById(id);
    }

    @Override
    public List<Menu> getMenuByUserId(String userID) {
        List<Menu> menuList = menuDao.selectMenuByUserId(userID);

        return menuList;
    }
}
